﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace JoePack
{

    public class Package
    {
        private List<File> _files;
     
        public Package()
        {
            
        }
        public string Name { get; set; }
        public string Description { get; set; }
        public string Version { get; set; }
        public string Source { get; set; }
       
        public List<JoePack.File> Files
        {
            get { return _files ?? (_files = new List<File>()); }
            set { 
                _files = value; 
            }
        }

        private List<Package> _dependentPackages;
        public List<Package> DependentPackages
        {
            get { return _dependentPackages ?? (_dependentPackages = new List<Package>()); ; }
            set { _dependentPackages = value; }
        }

        public void AddFile(File file)
        {
            file.Package = this;
            Files.Add(file);
        }
    }

    public class File
    {
        public File()
        {}

        public File(string source)
        {
            this.Source = source;
        }

        
        public Package Package { get; set; }
        public string Source { get; set; }

        public string SourcePath
        {
            get { 
                if (Path.IsPathRooted(this.Source))
                {
                    return this.Source;
                }
                return Path.Combine(Package.Source, this.Source);
            }
        }

        public string FileName
        {
            get { return Path.GetFileName(this.Source); }
        }
    }
}
